package entity;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name = "prog_post")
public class Post {
	
	private Long id;
	private String name;
	private String text;
	private Date creationdate;
	private User user;
	private Taxonomy taxonomy;
	
	public Post() {
		
	}

	public Post(String name, String text, Date creationdate) {
		super();
		this.name = name;
		this.text = text;
		this.creationdate = creationdate;
	}

	public Post(String name, String text, Date creationdate, User user,
			Taxonomy taxonomy) {
		super();
		this.name = name;
		this.text = text;
		this.creationdate = creationdate;
		this.user = user;
		this.taxonomy = taxonomy;
	}
	
	@Id
	@SequenceGenerator(name = "Post_gen", sequenceName = "Post_index")
	@GeneratedValue(generator = "Post_gen", strategy = GenerationType.SEQUENCE)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public Date getCreationdate() {
		return creationdate;
	}

	public void setCreationdate(Date creationdate) {
		this.creationdate = creationdate;
	}
	
	@ManyToOne(cascade = CascadeType.ALL)
	@JoinColumn(name = "fk_userid")
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
	@ManyToOne(cascade = CascadeType.ALL)
	@JoinColumn(name = "fk_taxonomyid")
	public Taxonomy getTaxonomy() {
		return taxonomy;
	}

	public void setTaxonomy(Taxonomy taxonomy) {
		this.taxonomy = taxonomy;
	}

	@Override
	public String toString() {
		return "Post [id=" + id + ", name=" + name + ", text=" + text
				+ ", creationdate=" + creationdate + ", user=" + user
				+ ", taxonomy=" + taxonomy + "]";
	}

}
